package com.yanzhu.service.mapper;

import com.yanzhu.service.model.User;
import org.apache.ibatis.annotations.*;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 16:02 2017/12/25
 * @Modified:
 */
@Mapper
public interface UserMapper {
    @Insert("insert into user(openId, nickname, avatar, gender, city, province, country, language) values(#{openId}, #{nickname}, #{avatar}, #{gender}, #{city}, #{province}, #{country}, #{language})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
    int insert(User user);

    @Select("select * from user where openId = #{openId}")
    User selectByOpenId(@Param("openId") String openId);

    @Select("select * from user where id = #{id}")
    User queryUserInfo(@Param("id") long uid);

    @Update("update user" +
            "  set nickname = #{nickname}," +
            "  avatar = #{avatar}," +
            "  gender = #{gender}," +
            "  city = #{city}," +
            "  province = #{province}," +
            "  country = #{country}," +
            "  language = #{language}" +
            "  where id = #{id}")
    void update(User user);
}
